package GenericLearn;


import org.junit.jupiter.api.Test;

import java.util.ArrayList;

/**
 * @author Lenl
 * @version v1.0
 * @create 2021-06-05 17:06
 * @description
 */
public class DIYGeneticTest {
    @Test
    public void test1(){
        DIYGeneric diy1=new DIYGeneric();
        diy1.setOrderT(123);
        diy1.setOrderT("123");//默认Object类型

        //建议实例化时指明泛型
        DIYGeneric<String> diy2=new DIYGeneric<>();
        diy2.setOrderT("123");
        System.out.println(diy2.getOrderT());

        //继承指明泛型后变成正常类
        Ex ex=new Ex();
        ex.setOrderT(123);
        System.out.println(ex.getOrderT());
        //若继承时不指明泛型，则仍是一个泛型类
    }

    @Test
    public void test3(){
        //泛型不同类型的引用不能相互赋值
        ArrayList<String> list1=new ArrayList<>();
        ArrayList<Integer> list2=new ArrayList<>();
        //list1.addAll(list2);//编译无法通过

        //泛型引用场景
        CustomerDAO d=new CustomerDAO();
        d.add(new Customer());
    }
    //静态方法中不能有泛型
    //异常类不能有泛型



}

class Ex extends DIYGeneric<Integer>{

}